//if the worker succeeded, do things that should be done after the completed stage
switch (obj.stage) {
case 1: //file read; create table query is to be made
var sDbName = Database.logicalDbName;
var aRet = SmExim.getCreateTableQuery(obj.tableName, sDbName, obj.columns, false);
if (aRet.error) {
SmExim.handleImportCompletion(-1);
return;
}
var params = {stage: 2};
params.createTableQuery = aRet.query;
params.tableName = aRet.tableName;
SmExim.importWorker.postMessage(params);
break;
case 2: //queries created; execution to be done
var answer = smPrompt.confirm(null, sm_getLStr("exim.confirm.rows.title"), sm_getLStr("exim.confirm.rows.msg") + obj.numRecords);
if(answer) {
if (obj.badLines.length > 0) {
var err = sm_getLFStr("exim.import.failed", [obj.badLines.length], 1) + obj.badLines.join(", ");
alert(err);
}
SmExim.showImportStatus("Importing: inserting " + obj.numRecords + " records in the database...");
//TODO: async might help
var bReturn = Database.executeTransaction(obj.queries);
//to use async, create query must be executed separately from insert queries (because, executeAsync expects array of statements, not strings; and createStatement fails if the table has not already been created.
// var bReturn = Database.executeAsync(obj.queries);
var sTabNameInInsert = Database.getPrefixedName(sTabName, sDbName);
var iFound = xmlTables.indexOf(sTabName);
if (iFound == -1) {
//last arg is true to indicate that user cannot edit column names needed until we can maintain arrays for original and new names like we do for tables using xmlTables & actualTables
var aRet = this.getCreateTableQuery(sTabName, sDbName, aCols, true);